package org.swfer.UIC 
{
	import flash.display.DisplayObject;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	
	/**
	 * 单选分组
	 * 必须部件 item0,item1~~itemn
	 * 回调事件 change
	 * @author swfer
	 */
	public class RadioButtonGroup extends ButtonGroup 
	{
		public static const CHANGE:String = 'change';
		
		protected var _selectIndex:int = -1;
		
		public function RadioButtonGroup(view:MovieClip) 
		{
			super(view);
		}
		
		override protected function init():void
		{
			itemDef = RadioButton;
			super.init();
		}
		
		override protected function onItemClick(e:MouseEvent):void 
		{
			var preIndex:int = _selectIndex;
			selectIndex = buttonViews.indexOf(e.currentTarget);
			if(preIndex!=_selectIndex) executeCallBack(CHANGE);
		}
		
		public function get selectIndex():int { return _selectIndex;}
		public function set selectIndex(value:int):void 
		{
			if (value >= buttons.length) throw new ArgumentError('超出索引');
			
			_selectIndex = value;
			for (var i:int = 0; i < buttons.length; i++) 
			{
				if (buttons[i].selected && _selectIndex == i) executeCallBack(CHANGE);
				buttons[i].selected = _selectIndex == i;
			}
		}
	}

}